package com.blue.validation.spi;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.blue.validation.Vin;

public class VinValidator implements ConstraintValidator<Vin,String>{

	private static Pattern pattern=Pattern.compile("^[A-Z0-9]{17}$");
	
	public VinValidator() {
	}

	@Override
	public void initialize(Vin constraintAnnotation) {
		
	}

	@Override
	public boolean isValid(String text, ConstraintValidatorContext context) {
		if(text==null || text.isEmpty())
			return true;
		Matcher matcher=pattern.matcher(text);
		return matcher.matches();
	}

}
